home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Unix / CNews / Source / relay / hdrdefs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-27  |  5.2 KB  |  173 lines

  1. /*
  2.  * Usenet header definitions (see ARPA Internet RFCs 1036 nee 850 & 822;
  3.  *    for a second opinion, see The Hideous Name by Pike & Weinberger).
  4.  *
  5.  * Headers are parsed and modified and copied in one pass.
  6.  * Nevertheless, the code is in pieces: hdrdefs.c, hdrparse.c, hdrmunge.c.
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <stddef.h>        /* must define offsetof */
  12. #include <sys/types.h>
  13.  
  14. #include "libc.h"
  15. #include "news.h"
  16. #include "headers.h"
  17. #include "hdrint.h"
  18.  
  19. /* required headers */
  20. static char msgnm[] =    "Message-ID:";    /* rejection of dup.s */
  21. static char ngsnm[] =    "Newsgroups:";    /* filing, clone for Xref */
  22. static char pathnm[] =    "Path:";    /* rejection, extend (damn) */
  23. static char subjnm[] =    "Subject:";    /* for ctl. msgs. */
  24. static char datenm[] =    "Date:";    /* rejection of stale art.s */
  25. static char fromnm[] =    "From:";    /* only required; no use */
  26.  
  27. /* optional headers */
  28. static char appnm[] =    "Approved:";    /* mod. groups */
  29. static char ctlnm[] =    "Control:";    /* ctl. msg.; NCMP */
  30. static char etctlnm[] =    "Also-Control:"; /* hybrid ctl. msg.; NCMP */
  31. static char expnm[] =    "Expires:";    /* history */
  32. static char distrnm[] =    "Distribution:";    /* transmission */
  33. static char sendnm[] =    "Sender:";    /* mod. groups */
  34. static char xrefnm[] =    "Xref:";    /* to *replace* (damn!)*/
  35.  
  36. /* obsolete "useful" headers */
  37. static char artnm[] =    "Article-I.D.:";    /* obs. Message-ID: */
  38.  
  39. /* obsolete useless headers: delete them all on contact */
  40. static char datercvnm[] = "Date-Received:";
  41. static char rcvnm[] =    "Received:";    /* obsolete Date-Received: */
  42. static char postnm[] =    "Posted:";    /* obsolete Date: */
  43. static char postversnm[] = "Posting-Version:";
  44. static char rlyversnm[] = "Relay-Version:";
  45. static char illobnm[] = "Illegal-Object:";    /* zmailer bitching */
  46.  
  47. static struct hdrdef msghdr = {
  48.     msgnm, STRLEN(msgnm), offsetof(struct headers, h_msgid) };
  49. static struct hdrdef ngshdr = {
  50.     ngsnm, STRLEN(ngsnm), offsetof(struct headers, h_ngs) };
  51. struct hdrdef pathhdr = {
  52.     pathnm, STRLEN(pathnm), offsetof(struct headers, h_path) };
  53. static struct hdrdef subjhdr = {
  54.     subjnm, STRLEN(subjnm), offsetof(struct headers, h_subj) };
  55. static struct hdrdef datehdr = {
  56.     datenm, STRLEN(datenm), offsetof(struct headers, h_date) };
  57. static struct hdrdef fromhdr = {
  58.     fromnm, STRLEN(fromnm), offsetof(struct headers, h_from) };
  59.  
  60. static struct hdrdef apphdr = {
  61.     appnm, STRLEN(appnm), offsetof(struct headers, h_approved) };
  62. static struct hdrdef ctlhdr = {                    /* NCMP */
  63.     ctlnm, STRLEN(ctlnm), offsetof(struct headers, h_ctlcmd) }; /* NCMP */
  64. static struct hdrdef etctlhdr = {                /* NCMP */
  65.     etctlnm, STRLEN(etctlnm), offsetof(struct headers, h_etctlcmd) }; /* NCMP */
  66. static struct hdrdef exphdr = {
  67.     expnm, STRLEN(expnm), offsetof(struct headers, h_expiry) };
  68. static struct hdrdef distrhdr = {
  69.     distrnm, STRLEN(distrnm), offsetof(struct headers, h_distr) };
  70. static struct hdrdef sendhdr = {
  71.     sendnm, STRLEN(sendnm), offsetof(struct headers, h_sender) };
  72. struct hdrdef xrefhdr = {
  73.     xrefnm, STRLEN(xrefnm), offsetof(struct headers, h_xref) };
  74.  
  75. static struct hdrdef arthdr = {
  76.     artnm, STRLEN(artnm), offsetof(struct headers, h_artid) };
  77.  
  78. static struct hdrdef datrcvhdr = { datercvnm, STRLEN(datercvnm), -1 };
  79. static struct hdrdef rcvhdr = { rcvnm, STRLEN(rcvnm), -1 };
  80. static struct hdrdef psthdr = { postnm, STRLEN(postnm), -1 };
  81. static struct hdrdef pstvrshdr = { postversnm, STRLEN(postversnm), -1 };
  82. static struct hdrdef rlyvrshdr = { rlyversnm, STRLEN(rlyversnm), -1 };
  83. static struct hdrdef illobjhdr = { illobnm, STRLEN(illobnm), -1 };
  84.  
  85. /* these are parsed into a struct headers */
  86.  
  87. hdrlist reqdhdrs = {
  88.     &msghdr,
  89.     &ngshdr,
  90.     &pathhdr,        /* modified by hdrmunge.c (emithdr()) */
  91.     &subjhdr,
  92.     &datehdr,
  93.     &fromhdr,
  94.     NULL
  95. };
  96. hdrlist opthdrs = {
  97.     &arthdr,        /* obsolete */
  98.     &apphdr,
  99.     &ctlhdr,        /* NCMP */
  100.     &etctlhdr,        /* NCMP */
  101.     &distrhdr,
  102.     &exphdr,
  103.     &sendhdr,
  104.     &xrefhdr,        /* for -b only */
  105.     NULL
  106. };
  107.  
  108. /*
  109.  * the following noxious headers are deleted on contact because neighbours
  110.  * still send them and they are big.  in an ideal world, they wouldn't be
  111.  * sent and thus we wouldn't need to delete them.
  112.  * It is tempting to delete Article-I.D.: too, but it may be too soon for that.
  113.  */
  114. hdrlist hdrvilest = {
  115.     &xrefhdr,        /* regenerated by fileart() if needed */
  116.     &datrcvhdr,
  117.     &rcvhdr,
  118.     &psthdr,
  119.     &pstvrshdr,
  120.     &rlyvrshdr,
  121.     &illobjhdr,
  122.     NULL,
  123. };
  124.  
  125. boolean headdebug = NO;
  126.  
  127. void
  128. hdrdebug(state)
  129. int state;
  130. {
  131.     headdebug = state;
  132. }
  133.  
  134. void
  135. hdrinit(hdrs)            /* zero all elements of hdrs */
  136. register struct headers *hdrs;
  137. {
  138.     hdrs->h_subj = NULL;
  139.     hdrs->h_ngs = NULL;
  140.     hdrs->h_distr = NULL;
  141.     hdrs->h_ctlcmd = NULL;        /* NCMP */
  142.     hdrs->h_etctlcmd = NULL;    /* NCMP */
  143.     hdrs->h_approved = NULL;
  144.     hdrs->h_msgid = NULL;
  145.     hdrs->h_artid = NULL;
  146.     hdrs->h_expiry = NULL;
  147.     hdrs->h_path = NULL;
  148.     hdrs->h_sender = NULL;
  149.     hdrs->h_from = NULL;
  150.     hdrs->h_date = NULL;
  151.     hdrs->h_xref = NULL;
  152. }
  153.  
  154. void
  155. freeheaders(hdrs)        /* free (assumed) malloced storage */
  156. register struct headers *hdrs;
  157. {
  158.     nnfree(&hdrs->h_subj);
  159.     nnfree(&hdrs->h_ngs);
  160.     nnfree(&hdrs->h_distr);
  161.     nnfree(&hdrs->h_ctlcmd);    /* NCMP */
  162.     nnfree(&hdrs->h_etctlcmd);    /* NCMP */
  163.     nnfree(&hdrs->h_approved);
  164.     nnfree(&hdrs->h_msgid);
  165.     nnfree(&hdrs->h_artid);
  166.     nnfree(&hdrs->h_expiry);
  167.     nnfree(&hdrs->h_path);
  168.     nnfree(&hdrs->h_sender);
  169.     nnfree(&hdrs->h_from);
  170.     nnfree(&hdrs->h_date);
  171.     nnfree(&hdrs->h_xref);
  172. }
  173.